package com.twu.biblioteca;

public class SecurityContext {

    private static final ThreadLocal<SecurityContext> INSTANCES = new ThreadLocal<SecurityContext>() {
        @Override
        protected SecurityContext initialValue() {
            return new SecurityContext();
        }
    };

    private static User user;

    public static SecurityContext get() {
        return INSTANCES.get();
    }

    public static void set(SecurityContext securityContext) {
        INSTANCES.set(securityContext);
    }

    public boolean isUserLoggedIn() {
        return user != null;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        SecurityContext.user = user;
    }

    public void clear() {
        SecurityContext.user = null;
    }

}
